import 'core-js/fn/object/assign';
import 'babel-polyfill'
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { browserHistory, hashHistory, Router } from 'react-router'
import { syncHistoryWithStore } from 'react-router-redux'
import { message } from 'antd'

import configureStore from './stores/configureStore'
import routes from './routes'

import './styles/style.less'

const preloadedState = {};
const store = configureStore(preloadedState)

const history = syncHistoryWithStore(hashHistory, store)

message.config({
  duration: 5,
});

// 注意 subscribe() 返回一个函数用来注销监听器
// store.subscribe(() => console.log(store.getState()))

// 重复点击菜单，页面刷新
function createElement(Component, props) {
  // 确保传入了所有的 props！
  return <Component key={Math.random()} {...props}/>
}

render(
  <Provider store={store}>
    <Router createElement={createElement} history={history} routes={routes} />
  </Provider>,
  document.getElementById('app')
)

